// templates/deliver/pages/sweep/sweep.js
import Toast from '@vant/weapp/toast/toast';
import Dialog from '@vant/weapp/dialog/dialog';
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        order_id: 0, //订单id
        order: [], //订单信息
        orderDetail: [], //订单商品信息
        activeNames: ['1'], //手风琴
        driverOrder: [], //订单绑定状态
        view_delivery_man_id: 0,
        view_driver_name: '',
        view_delivery_district_id: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let view_delivery_man_id = wx.getStorageSync('view_delivery_man_id') || 0
        let view_driver_name = ''
        let view_delivery_district_id = 0
        if (view_delivery_man_id > 0) {
            view_driver_name = wx.getStorageSync('view_driver_name')
            view_delivery_district_id = wx.getStorageSync('view_delivery_district_id')
        }

        this.setData({
            view_delivery_man_id,
            view_driver_name,
            view_delivery_district_id
        })
        //获取页面传递的订单id
        this.setData({
            order_id: options.order_id,
        })
        
        this.orderSelect();
    },
    //手风琴控制
    onChange(event) {
        this.setData({
            activeNames: event.detail,
        });
    },
    /*
     * 根据订单id查询所有订单信息
     */
    async orderSelect(e) {
        var order_id = this.data.order_id;
        var mall_id = app.globalData.mall_id;
        const {
            data: res
        } = await wx.p.request({
            url: app.globalData.URL + '/deliver.order/getByidOrderAll?order_id=' + order_id + '&mall_id=' + mall_id,
            method: 'GET'
        })
        console.log(res)
        this.setData({
            order: res.data.data,
            orderDetail: res.data.data.orderDetailAll,
            driverOrder: res.data.result,
        })
    },
    /**
     * 点击导航到店
     */
    guidepath() {
        //获取经纬度，获取到的是个字符串
        let str = this.data.order['location'];
        let name = this.data.order['name'];
        let mobile = this.data.order['mobile'];
        let address = this.data.order['address'];
        //开始分割 
        var divide = str.split(',');
       
        wx.openLocation({
            name: name + mobile,
            address: address,
            latitude: Number(divide[1]),
            longitude: Number(divide[0]),
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})